#pragma once
#include "CourbeBezier.h"
#include <vector>
using namespace std;
class SurfaceBezier
{
private:
	Tableaux<CourbeBezier> _carreau;
	Tableaux<FacesP> _solide;
	vector<vector<Points3D>> _surface;
	
	
public:
	SurfaceBezier();
	SurfaceBezier(int nBPtCtrl);
	SurfaceBezier(SurfaceBezier &s);
	SurfaceBezier(Tableaux<CourbeBezier> surface);
	virtual ~SurfaceBezier();

	//Surcharge operateur
	CourbeBezier & operator [](int i);

	//Methodes
	void ajoutCourbe(const CourbeBezier & courbe, int pos);
	Points3D evaluer(double u,double v);
	Points3D & getPoint(int i, int j);
	Tableaux<FacesP> & getSolide();
	void genererSurface(int largeur,int longeur);
	void triangulerSurface(AttributsFaces *af);
	void decoupage(SolidesP &,Tableaux<FacesP> &entre,Tableaux<FacesP> &sortie);
private:
	void creerFace(int l, int h,AttributsFaces *af);
	static bool SurfaceBezier::SubdivisionFaceTriangulaire(FacesP face,FacesP *tabFaces);
	static bool centreFaceDansEnglobant(Englobants3D &englobant,FacesP &face);
	static void intersection(Englobants3D & englobant,Tableaux<FacesP> & faces,Tableaux<FacesP> & sortie);
	static void construireFaceTriangulaire(Points3D &p1,Points3D &p2,Points3D &p3,FacesP &face,const AttributsFacesP *af);
	static void determinerCas(Englobants3D & englobant, FacesP &face, int &cas, int *sommet);
	static bool centreTriangle(Tableaux<AretesP> & aretes,Points3D & point);
	static Points3D milieuSegment3D(AretesP & arete);
	static bool centreTriangle(FacesP & face,Points3D & point);
	static void contruireFaceRectangulaire(Points3D *points,FacesP &face,const AttributsFacesP *af);
	static void decouperFaceCas2(FacesP & face,SolidesP &solide,Tableaux<FacesP> &sortie,int *sommet);
	static void decouperFaceCas1(FacesP & face,SolidesP &solide,Tableaux<FacesP> &sortie,int sommet);
};
